#include <REGX52.H>
#include "Timer1.h"

sbit Motor = P1^0;


unsigned char Compare,Motor_Count;


/**
  * @brief  电机初始化
  * @param  无
  * @retval 无
  */
void Motor_Init()
{
	Timer1_Init();
}


/**
  * @brief  电机设置速度
  * @param  Speed 要设置的速度，范围0~100
  * @retval 无
  */
void Motor_SetSpeed(unsigned char Speed)
{
	Compare = Speed;
}



//定时器1中断函数
void Timer1_Rountine() interrupt 3
{		
	TL1 = 0xA4;		//设置定时初值
	TH1 = 0xFF;		//设置定时初值
	
	Motor_Count++;
	Motor_Count %= 100;
	if (Motor_Count < Compare)
	{
		Motor = 1;
	}
	else
	{
		Motor = 0;
	}
}








